/*
 * Copyright (c) 2021.版权所有高金磊
 */

package 领扣算法.A简单题.重塑矩阵;

import orther.JavaPy;

public class Main {
    public int[][] matrixReshape(int[][] nums, int r, int c) {
        if (nums.length == 0 || r * c != nums.length * nums[0].length)
            return nums;
        //层次遍历
        int[][] res = new int[r][c];
        int n = 0;
        for (int[] num : nums) {
            for (int i : num) {
                res[n / c][n % c] = i;
                n++;
            }
        }
        return res;
    }
}
